using System.Drawing;

namespace GDI
{
    public class ImagePlotter : PrintableItem
    {
        private Image f_Image;
        private VerticalAlign f_VerticalAlign;
        private HorizontalAlign f_HorizontalAlign;

        public ImagePlotter(Image image, VerticalAlign VerticalAlign = VerticalAlign.Center,
            HorizontalAlign HorizontalAlign = HorizontalAlign.Center)
        {
            f_HorizontalAlign = HorizontalAlign;
            f_VerticalAlign = VerticalAlign;
            f_Image = image;
        }

        protected override void Draw(Graphics g)
        {
            var lv_Image = f_Image;
            var x = 0f;
            var y = 0f;
            var size = lv_Image.Size;
            var width = size.Width;
            var height = size.Height;

            switch(f_HorizontalAlign)
            {
                case HorizontalAlign.Center:
                    x = (float)(-width / 2.0);
                    break;
                case HorizontalAlign.Right:
                    x = -width;
                    break;
            }

            switch(f_VerticalAlign)
            {
                case VerticalAlign.Center:
                    y = (float)(-height / 2.0);
                    break;
                case VerticalAlign.Bottom:
                    y = -height;
                    break;
            }

            g.DrawImage(lv_Image, x, y);
        }
    }
}